home *** CD-ROM | disk | FTP | other *** search
/ Programming Windows (5th Edition) / Programming Windows, 5th ed. - Companion CD (097-0002183)(1999).iso / Chap11 / About1 / About1.c next >
Encoding:
C/C++ Source or Header  |  1998-10-09  |  2.9 KB  |  101 lines

  1. /*------------------------------------------
  2.    ABOUT1.C -- About Box Demo Program No. 1
  3.                (c) Charles Petzold, 1998
  4.    ------------------------------------------*/
  5.  
  6. #include <windows.h>
  7. #include "resource.h"
  8.  
  9. LRESULT CALLBACK WndProc      (HWND, UINT, WPARAM, LPARAM) ;
  10. BOOL    CALLBACK AboutDlgProc (HWND, UINT, WPARAM, LPARAM) ;
  11.  
  12. int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
  13.                     PSTR szCmdLine, int iCmdShow)
  14. {
  15.      static TCHAR szAppName[] = TEXT ("About1") ;
  16.      MSG          msg ;
  17.      HWND         hwnd ;
  18.      WNDCLASS     wndclass ;
  19.      
  20.      wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
  21.      wndclass.lpfnWndProc   = WndProc ;
  22.      wndclass.cbClsExtra    = 0 ;
  23.      wndclass.cbWndExtra    = 0 ;
  24.      wndclass.hInstance     = hInstance ;
  25.      wndclass.hIcon         = LoadIcon (hInstance, szAppName) ;
  26.      wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
  27.      wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
  28.      wndclass.lpszMenuName  = szAppName ;
  29.      wndclass.lpszClassName = szAppName ;
  30.      
  31.      if (!RegisterClass (&wndclass))
  32.      {
  33.           MessageBox (NULL, TEXT ("This program requires Windows NT!"),
  34.                       szAppName, MB_ICONERROR) ;
  35.           return 0 ;
  36.      }
  37.      
  38.      hwnd = CreateWindow (szAppName, TEXT ("About Box Demo Program"),
  39.                           WS_OVERLAPPEDWINDOW,
  40.                           CW_USEDEFAULT, CW_USEDEFAULT,
  41.                           CW_USEDEFAULT, CW_USEDEFAULT,
  42.                           NULL, NULL, hInstance, NULL) ;
  43.      
  44.      ShowWindow (hwnd, iCmdShow) ;
  45.      UpdateWindow (hwnd) ; 
  46.      
  47.      while (GetMessage (&msg, NULL, 0, 0))
  48.      {
  49.           TranslateMessage (&msg) ;
  50.           DispatchMessage (&msg) ;
  51.      }
  52.      return msg.wParam ;
  53. }
  54.  
  55. LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  56. {
  57.      static HINSTANCE hInstance ;
  58.      
  59.      switch (message)
  60.      {
  61.      case WM_CREATE :
  62.           hInstance = ((LPCREATESTRUCT) lParam)->hInstance ;
  63.           return 0 ;
  64.           
  65.      case WM_COMMAND :
  66.           switch (LOWORD (wParam))
  67.           {
  68.           case IDM_APP_ABOUT :
  69.                DialogBox (hInstance, TEXT ("AboutBox"), hwnd, AboutDlgProc) ;
  70.                break ;
  71.           }
  72.           return 0 ;
  73.           
  74.      case WM_DESTROY :
  75.           PostQuitMessage (0) ;
  76.           return 0 ;
  77.      }
  78.      return DefWindowProc (hwnd, message, wParam, lParam) ;
  79. }
  80.  
  81. BOOL CALLBACK AboutDlgProc (HWND hDlg, UINT message, 
  82.                             WPARAM wParam, LPARAM lParam)
  83. {
  84.      switch (message)
  85.      {
  86.      case WM_INITDIALOG :
  87.           return TRUE ;
  88.           
  89.      case WM_COMMAND :
  90.           switch (LOWORD (wParam))
  91.           {
  92.           case IDOK :
  93.           case IDCANCEL :
  94.                EndDialog (hDlg, 0) ;
  95.                return TRUE ;
  96.           }
  97.           break ;
  98.      }
  99.      return FALSE ;
  100. }
  101.